<?php
class Product_Core {
	
	protected $table_name = 'products';
	protected $primary_key = 'products_id';
	protected $col_sort_order = 'products_sort_order';
	protected $col_status = 'products_status';
	protected $sorting = array('products_sort_order' => 'desc','products_id' => 'desc');
	public $db;
    
    public function __construct()
    {
        $this->db = Database::instance();     
    }
    
    public function get($model='',$id='')
    {
        if($id) $this->db->where($this->table_name.'.'.$this->primary_key,$id);
        $mlist = $model->get();
		for($i=0; $i<count($mlist); $i++)
		{
			$model_lang = new Language_Model();			
			$list_lang = $model_lang->get_with_active();
			for($j=0; $j<count($list_lang); $j++)
			{
				$model_des = new Product_description_Model();
				$list = $model_des->get($mlist[$i]['products_id'],$list_lang[$j]['languages_id']);
				if($list){
					$list = array_merge($mlist[$i],$list[0]);				
				}
				$list_lang[$j] = $list;
			}
			$mlist[$i]['languages'] = $list_lang;			
		}		
		return $mlist;
    }
}
?>